"""
用户相关模型
"""
from datetime import datetime
from sqlalchemy import Column, Integer, String, Text, DateTime, SmallInteger, JSON
from app.db.session import Base


class AdminUser(Base):
    """管理员表"""
    __tablename__ = "admin_users"
    
    id = Column(Integer, primary_key=True, index=True, comment="主键ID")
    username = Column(String(50), unique=True, nullable=False, index=True, comment="用户名")
    email = Column(String(100), unique=True, nullable=False, index=True, comment="邮箱")
    password_hash = Column(String(255), nullable=False, comment="密码哈希")
    nickname = Column(String(50), comment="昵称")
    avatar = Column(String(255), comment="头像URL")
    role_id = Column(Integer, comment="角色ID")
    status = Column(SmallInteger, default=1, comment="状态: 1启用 0禁用")
    last_login_time = Column(DateTime, comment="最后登录时间")
    created_at = Column(DateTime, default=datetime.now, comment="创建时间")
    updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment="更新时间")


class Role(Base):
    """角色表"""
    __tablename__ = "roles"
    
    id = Column(Integer, primary_key=True, index=True, comment="主键ID")
    name = Column(String(50), nullable=False, comment="角色名称")
    description = Column(String(255), comment="角色描述")
    permissions = Column(JSON, comment="权限列表")
    created_at = Column(DateTime, default=datetime.now, comment="创建时间")
    updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment="更新时间")

